#include "dunCommandParser.h"

void	commandWait(t_graph g)
{
	char buff[1024];
	while (scanf("%s", buff) != EOF)
	{
		if (!strcmp(buff, "COST"))
			commandCost(g);
		if (!strcmp(buff, "PATH"))
			commandPath(g);
	}
}


void	commandCost(t_graph g)
{
	char buff[1024], *tmp;
	int life = 0, i, result;
	dunQueue f = queueNew();
	t_lex lex = lexerCreate();
	
	scanf("%d", &life);
	scanf("%s", buff);
	if (buff[0] == '[')
	{
		lexerSplit(lex, &buff[1], ";]");
		tmp = lexerGetToken(lex);
		while (tmp)
		{
			i = strtol(tmp, NULL, 10);
			if (i != 0)
			{
				f = queuePush(i, f); 
			}
				
			tmp = lexerGetToken(lex);
		}
		result = graphComputeCost(g, life, f);
		switch (result)
		{
			case _DEAD_: printf("DEAD\n"); break;
			case _NP_: printf("NP\n"); break;
			default: printf("%d\n", result); break;
		}
	}
}

void	commandPath(t_graph g)
{
	int life, s, d;
	dunQueue f;
	scanf("%d %d %d", &life, &s, &d);
	
	f = graphSeekPath(g, life, s, d);
	if (queueIsEmpty(f))
	{
		printf("NP\n");
	}
	else
	{
		printf("[");
		while (f->next)
		{
			s = stackPop(&f);
			printf("%d;", s);
		}
		s = stackPop(&f);
		printf("%d]\n",s);
	}
}